import 'package:flutter/cupertino.dart';
import 'package:flutter_ohos/app/common/widgets/toast.dart';
import 'package:flutter_ohos/app/modules/counter_method_channel.dart';
import 'package:flutter_ohos/app/utils/log_utils.dart';
import 'package:provider/provider.dart';

enum FoldStatus {
  folded,
  half_folded,
  expanded
}

class FoldStatusProvider extends ChangeNotifier {
  /// 默认折叠态
  var foldStatus;
  var screenWidth;

  void init () {
    ///监听原生侧channel
    Channel.methodChannel.setMethodCallHandler((call) =>
        Future(() {
          if (call.method == 'foldStatus') {
            var status = call.arguments["status"];
            var width = call.arguments["windowWidth"];

            LogUtils.d("Flutter侧接收到的设备折叠态：${status}");

            if (status == "folded") {
              ///折叠态
              foldStatus = FoldStatus.folded;
            }else if (status == "expanded" || status == "half_folded") {
              ///展开态
              foldStatus = FoldStatus.expanded;
            }

            screenWidth = double.parse(width);
            notifyListeners();

          }
        }));
  }


}